<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">

<!-- 
	Subversion HTML Generation Transform
	 by Greg
	
	This transform will take the output from 
	 "svn log -v -r low:high --xml "repo/path" 
	and produce a pretty html with the log messages.
	
-->

<xsl:template match="log">
	<html>
		<head>
			<title>Subversion Logs</title>
			<style type="text/css">
				/*Shamelessly stole css from websvn repo template*/
				table 
				{
					width: 100%;
					border-collapse: collapse;
					margin: 1em 0 0 0;
					border: 2px solid #e0e0e0;
					background: #e8e8ff;
					border-bottom: 1px solid #000080;
					padding-top: 0.5em;
				}
				td 
				{
					padding: 0.25em 0.5em 0.25em 0.5em;
					vertical-align: top;
					border-bottom: 2px solid #f0f0f0;
				}
				td.title
				{
					text-align: center;
					font-weight: bold;
					background: #f2f2ff;
					border-bottom: 2px solid #e0e0f0;
				}
				tr.row-1 
				{
					background-color: #fcfcff;
				}
				tr.row-0 
				{
					background-color: #f8f8ff;
				}
				
			</style>
		</head>
		<body>
			<table>
			<tr>
				<td class="title">Rev</td>
				<td class="title">Author</td>
				<td class="title">Date</td>
				<td class="title">Log Message</td>
			</tr>
			
			<xsl:for-each select="logentry">
			
			<tr>
				<xsl:choose>
					<xsl:when test="position() mod 2 != 1">
						<xsl:attribute  name="class">row-0</xsl:attribute>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute  name="class">row-1</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				
				<td><xsl:value-of select="@revision"/></td>
				<td><xsl:value-of select="author"/></td>
				<!--<td><xsl:value-of select="date"/></td>-->
				<td>
					<xsl:call-template name="prettydate">
						<xsl:with-param name="date"><xsl:value-of select="date" /></xsl:with-param>
					</xsl:call-template>
				</td>
				<td><xsl:value-of select="msg"/></td>
			</tr>
			
			</xsl:for-each>
			
			</table>
		</body>
	</html>
	
</xsl:template>

<xsl:template name="prettydate">
	<xsl:param name="date" />
	<!-- Date -->
	<xsl:value-of select="substring($date,6,2)" />
	<xsl:text>/</xsl:text>
	<xsl:value-of select="substring($date,9,2)" />
	<xsl:text>/</xsl:text>
	<xsl:value-of select="substring($date,1,4)" />
	<xsl:text> </xsl:text>
	
	<!-- 
		Time 
		I am lazy and just hard coded in the 
		time zone switch. 
	-->
	<xsl:variable name="hour24">
		<xsl:choose>
			<xsl:when test="((substring($date,12,2) - 6) mod 24) &lt; 0">
				<xsl:value-of select="24 + ((substring($date,12,2) - 6) mod 24)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="((substring($date,12,2) - 6) mod 24)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	<!-- Hours -->
	<xsl:choose>
		<xsl:when test="$hour24 = 0">
			<xsl:text>12</xsl:text>
		</xsl:when>
		<xsl:when test="$hour24 &lt; 13">
			<xsl:value-of select="$hour24" />
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$hour24 - 12" />
		</xsl:otherwise>
	</xsl:choose>
	
	<xsl:text>:</xsl:text>
	<!-- Minutes -->
	<xsl:value-of select="substring($date,15,2)" />
	<xsl:text>:</xsl:text>
	<!-- Seconds -->
	<xsl:value-of select="substring($date,18,2)" />
	
	<!-- Figure out if it is A.M. or P.M. -->
	<xsl:choose>
		<xsl:when test="$hour24 &lt; 13">
			<xsl:text> A.M.</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text> P.M.</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>